<?php
error_reporting(0);
session_start();
include_once '../comm/config.php';
include_once '../comm/checkpostandget.php';
include_once 'check.php';
include_once 'page.class.php';
include_once '../comm/wjt.php';

function tgyj($top_name,$down_name){
	global $BIAOTOU;
    $sql="SELECT sum(je) as tgyj FROM `".$BIAOTOU."mingxi` WHERE `ddusername`='$top_name' and `memo` like '交易人$down_name%'";
	$query=mysql_query($sql);
	$row=mysql_fetch_array($query);
	return $row[0]?$row[0]:0;
}

function buy_num($uid){
	global $BIAOTOU;
    $sql="select count(Id) from ".$BIAOTOU."tradelist where outer_code='".$uid."' and checked=2";
	$query=mysql_query($sql);
	$row=mysql_fetch_array($query);
	$tao_num=$row[0]?$row[0]:0;
	
	$sql="select count(id) from ".$BIAOTOU."mall_order where u_id='".$uid."' and stat_desc='核对有效'";
	$query=mysql_query($sql);
	$row=mysql_fetch_array($query);
	$mall_num=$row[0]?$row[0]:0;
	
	return $tao_num+$mall_num;
}

$pagesize=10;
$page = !($_GET['page'])?'1':intval($_GET['page']);
$page2=($page-1)*$pagesize;
$q = "SELECT * FROM ".$BIAOTOU."user where tjr='".$_SESSION["dduserid"]."'";
$rsin01 = mysql_query($q);
$total=mysql_num_rows($rsin01);
$q = "SELECT * FROM ".$BIAOTOU."user where tjr='".$_SESSION["dduserid"]."' order by loginnum desc limit ".$page2.",".$pagesize;
$rs = mysql_query($q);
while($row=mysql_fetch_array($rs)){
	$arr[$i]=$row;
	$arr[$i]['tgyj']=tgyj($_SESSION['duoduouser'],$row['ddusername']);
	$i++;
}

$tag="center";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>推广赚钱 - 用户中心</title>
<link href="../css/usercss.css" rel="stylesheet" type="text/css">
<link href="../template/<?=MOBAN?>/css/common.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../js/jquery.js"></script>
</HEAD>

<BODY id="tuiguang">
<?php
include("../template/".MOBAN."/header.tpl.php");
?>
<?php
include("../template/".MOBAN."/nav.tpl.php");
?>
<div id="main">
<?php
include("left.php");
?>
<div class="contain">
  <h2 class="left_nav3">我推广的好友</h2><span style="font-size:12px; height:24px; line-height:24px; padding-left:10px; color:#dd0000; background:url(../images/tip.gif) no-repeat;">推广成功的好友，只要他从本站去淘宝购物，您每次都可以获取其返还佣金的<?=round(TGBL/FXBL,2)*100?>%作为您的推广佣金！</span>
    <div class="order">
      <div class="title">
          <ul>
            <li><a style="MARGIN-LEFT: 10px" href="tuiguang_url.php">我要推广</a></li>
			<li><a style="MARGIN-LEFT: 10px" class="current" href="tuiguang.php">我推广的好友</a></li>			
          </ul>
      </div>
	  <div class="content">
      <ul style="width:710px">
          <li class="order_title">
          	<div class="item" style="width:150px;">&nbsp;&nbsp;用户名</div>
            <div class="item" style="width:150px; text-align:center">已获佣金(仅参考)</div>
            <div class="item" style="width:140px; text-align:center">登录次数</div>
            <div class="item" style="width:150px; text-align:center">购买次数</div>
			<div class="item" style="width:120px; text-align:center">注册时间</div>
		  </li>
		<?php foreach($arr as $arr){?>
		<li class="order_detail">
          	<div class="item" style="width:150px;">&nbsp;&nbsp;<?=$arr['ddusername']?></div>
            <div class="item" style="width:150px; text-align:center">
			<?=round($arr['tgyj'],2)?></div>
            <div class="item" style="width:140px; text-align:center"><?=$arr['loginnum']?></div>
            <div class="item" style="width:150px; text-align:center"><?=buy_num($arr['Id'])?></div>
			<div class="item" style="width:120px; text-align:center"><?=$arr['regtime']?></div>
        </li>
		<?php }?>
      </ul>
    </div>
  </div>
</div>
<div class="megas512"><?php pageft($total,$pagesize,1,1,0,10,"tuiguang.php?keyword=".$keyword);	echo $pagenav;?></div>
<DIV class=clear></DIV></DIV>
<?php
include("../template/".MOBAN."/footer.tpl.php");
mysql_close();
?>
</BODY></HTML>
